package com.fanbai.score.business.http;

import android.content.Context;

import com.fanbai.score.business.beans.ShopInfo_Bean;
import com.fanbai.score.business.beans.StaffInfo_Bean;
import com.fanbai.score.common.Utils.JsonUtils;
import com.fanbai.score.common.http.CallBack;
import com.fanbai.score.common.http.HttpUtils;
import com.fanbai.score.common.http.WebCodes;
import com.fanbai.score.user.bean.HeadImage_Bean;
import com.fanbai.score.user.bean.User_Bean;
import com.tencent.bugly.crashreport.CrashReport;

import java.util.HashMap;
import java.util.List;

/**
 * Created by acer on 2017/6/18.
 */

public class Busin_Goods_RequestNet {


    /**
     * 获取所有商铺今日销售信息
     * @param ctx
     * @param callBack
     */
    public static void gettotalpricefortoday(final Context ctx, final CallBack<String> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "gettotalpricefortoday");
        String url = WebCodes.HTTP_URL_BUSIN_SHOP ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                        callBack.onSuccess(ret, msg, body);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }

    /**
     * 2、获取所有商铺
     * @param ctx
     * @param callBack
     */
    public static void getshopinfos(final Context ctx, final CallBack<List<ShopInfo_Bean>> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "getshopinfos");
        String url = WebCodes.HTTP_URL_BUSIN_SHOP ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                    List<ShopInfo_Bean> beans = JsonUtils.toArr(body, ShopInfo_Bean[].class);
                    callBack.onSuccess(ret, msg, beans);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }

    /**
     * 添加商铺
     * @param ctx
     * @param sname
     * @param sdetailaddress
     * @param slinkmanname
     * @param slinkmanmobile
     * @param callBack
     */
    public static void addshopinfo(final Context ctx, String sname, String sdetailaddress, String slinkmanname, String slinkmanmobile, final CallBack<String> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "addshopinfo");
        params.put("sname", sname);
        params.put("sdetailaddress", sdetailaddress);
        params.put("slinkmanname", slinkmanname);
        params.put("slinkmanmobile", slinkmanmobile);
        String url = WebCodes.HTTP_URL_BUSIN_SHOP ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                    callBack.onSuccess(ret, msg, body);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }

    /**
     * 编辑商铺
     * @param ctx
     * @param sname
     * @param sdetailaddress
     * @param slinkmanname
     * @param slinkmanmobile
     * @param callBack
     */
    public static void editshopinfo(final Context ctx, String sid, String sname, String sdetailaddress, String slinkmanname, String slinkmanmobile, final CallBack<String> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "editshopinfo");
        params.put("sid", sid);
        params.put("sname", sname);
        params.put("sdetailaddress", sdetailaddress);
        params.put("slinkmanname", slinkmanname);
        params.put("slinkmanmobile", slinkmanmobile);
        String url = WebCodes.HTTP_URL_BUSIN_SHOP ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                    callBack.onSuccess(ret, msg, body);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }

    /**
     * 获取商铺店员列表
     * @param ctx
     * @param sid
     * @param callBack
     */
    public static void getshopclerkinfos(final Context ctx, String sid, final CallBack<List<StaffInfo_Bean>> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "getshopclerkinfos");
        params.put("sid", sid);
        String url = WebCodes.HTTP_URL_BUSIN_SHOP ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                    List<StaffInfo_Bean> beans = JsonUtils.toArr(body, StaffInfo_Bean[].class);
                    callBack.onSuccess(ret, msg,beans);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }

}
